package com.zrq.secondkill.response;


import com.zrq.secondkill.error.BusinessErrorEnum;
import lombok.Data;


/**
 * 即使出错,也应该让前端得到符合正常格式的信息,以便调试
 */
@Data
public class CommonReturnType {
    /**
     * "success"或"failed"
     */
    private String status;

    /**
     * 若status为success,应为相应数据
     * 若status为failed,应为 {@link BusinessErrorEnum}
     */
    private Object data;

    public static CommonReturnType create(String status, Object data) {
        CommonReturnType commonReturnType = new CommonReturnType();
        commonReturnType.setStatus(status);
        commonReturnType.setData(data);
        return commonReturnType;
    }

    public static CommonReturnType create(Object data) {
        CommonReturnType commonReturnType = new CommonReturnType();
        commonReturnType.setStatus("success");
        commonReturnType.setData(data);
        return commonReturnType;
    }

}
